package cn.com.scitc.servlet.data_interface;

import cn.com.scitc.dao.PaidDao;
import cn.com.scitc.model.Paid;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@WebServlet("/dataInterface/paid/list")
public class PaidListInterface extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, Object> result = new HashMap<>();

        try {
            PaidDao paidDao = new PaidDao();
            List<Paid> list = paidDao.findAll();

            result.put("msg", "查询成功");
            result.put("code", 0);
            result.put("list", list);
        }
        catch (Exception er) {
            result.put("msg", "查询失败");
            result.put("code", 1);
        }

        String jsonString = JSON.toJSONString(result);
        resp.setContentType("text/json;charset=UTF-8");
        PrintWriter writer = resp.getWriter();
        writer.println(jsonString);
        writer.close();
    }
}
